]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
PopupMenu: enhance PopupSwitchMenuItem to show status labels
authorGiovanni Campagna <gcampagna@src.gnome.org>
Thu, 21 Apr 2011 14:44:28 +0000 (16:44 +0200)
committerGiovanni Campagna <gcampagna@src.gnome.org>
Mon, 27 Jun 2011 15:21:38 +0000 (17:21 +0200)
Moves and converts NMDeviceTitleMenuItem from network.js into
PopupSwitchMenuItem, so that it can show both a switch and a
greyed-out status label. This will be soon used by the Bluetooth menu.

https://bugzilla.gnome.org/show_bug.cgi?id=648048

data/theme/gnome-shell.css
js/ui/popupMenu.js
js/ui/status/network.js

index e5bed0d39fb2e0fd7c0bec5ac47bc8495ac29615..7e7e7860d8ba2cd6822a16c2ec6ca7d311320103 100644 (file)
@@ -187,6 +187,7 @@ StTooltip StLabel {
 }
 
 .popup-inactive-menu-item {
+    font-weight: normal;
     color: #999;
 }
 
index 84089d63804b108ff2157fc031482c518abf5a0a..3d854ef7da62af5b779280508cfe537d2a520982 100644 (file)
@@ -704,11 +704,36 @@ PopupSwitchMenuItem.prototype = {
         this._switch = new Switch(active);
 
         this.addActor(this.label);
-        this.addActor(this._switch.actor, { align: St.Align.END });
 
-        this.connect('activate', Lang.bind(this,function(from) {
+        this._statusBin = new St.Bin({ x_align: St.Align.END });
+        this.addActor(this._statusBin, { align: St.Align.END });
+
+        this._statusLabel = new St.Label({ text: '',
+                                           style_class: 'popup-inactive-menu-item'
+                                         });
+        this._switch = new Switch(false);
+        this._statusBin.child = this._switch.actor;
+    },
+
+    setStatus: function(text) {
+        if (text != null) {
+            this._statusLabel.text = text;
+            this._statusBin.child = this._statusLabel;
+            this.actor.reactive = false;
+            this.actor.can_focus = false;
+        } else {
+            this._statusBin.child = this._switch.actor;
+            this.actor.reactive = true;
+            this.actor.can_focus = true;
+        }
+    },
+
+    activate: function(event) {
+        if (this._switch.actor.mapped) {
             this.toggle();
-        }));
+        }
+
+        PopupBaseMenuItem.prototype.activate.call(this, event);
     },
 
     toggle: function() {
index 3983703c586fc5521c81aaf88d45a656159f3dbe..348fcd49d5df446b4fc7b32e317f178ac1bd160a 100644 (file)
@@ -196,68 +196,18 @@ NMNetworkMenuItem.prototype = {
     }
 };
 
-function NMDeviceTitleMenuItem() {
-    this._init.apply(this, arguments);
-}
-
-NMDeviceTitleMenuItem.prototype = {
-    __proto__: PopupMenu.PopupBaseMenuItem.prototype,
-
-    _init: function(description, params) {
-        PopupMenu.PopupBaseMenuItem.prototype._init.call(this, params);
-
-        this._descriptionLabel = new St.Label({ text: description,
-                                                style_class: 'popup-subtitle-menu-item'
-                                              });
-        this.addActor(this._descriptionLabel);
-
-        this._statusBin = new St.Bin({ x_align: St.Align.END });
-        this.addActor(this._statusBin, { align: St.Align.END });
-
-        this._statusLabel = new St.Label({ text: '',
-                                           style_class: 'popup-inactive-menu-item'
-                                         });
-        this._switch = new PopupMenu.Switch(false);
-        this._statusBin.child = this._switch.actor;
-    },
-
-    setStatus: function(text) {
-        if (text != null) {
-            this._statusLabel.text = text;
-            this._statusBin.child = this._statusLabel;
-            this.actor.reactive = false;
-            this.actor.can_focus = false;
-        } else {
-            this._statusBin.child = this._switch.actor;
-            this.actor.reactive = true;
-            this.actor.can_focus = true;
-        }
-    },
-
-    activate: function(event) {
-        if (this._switch.actor.mapped) {
-            this._switch.toggle();
-            this.emit('toggled', this._switch.state);
-        }
-
-        PopupMenu.PopupBaseMenuItem.prototype.activate.call(this, event);
-    },
-
-    get state() {
-        return this._switch.state;
-    },
-
-    setToggleState: function(newval) {
-        this._switch.setToggleState(newval);
-    }
-};
-
 function NMWiredSectionTitleMenuItem() {
     this._init.apply(this, arguments);
 }
 
 NMWiredSectionTitleMenuItem.prototype = {
-    __proto__: NMDeviceTitleMenuItem.prototype,
+    __proto__: PopupMenu.PopupSwitchMenuItem.prototype,
+
+    _init: function(label, params) {
+        params = params || { };
+        params.style_class = 'popup-subtitle-menu-item';
+        PopupMenu.PopupSwitchMenuItem.prototype._init.call(this, label, false, params);
+    },
 
     updateForDevice: function(device) {
         if (device) {
@@ -269,7 +219,7 @@ NMWiredSectionTitleMenuItem.prototype = {
     },
 
     activate: function(event) {
-        NMDeviceTitleMenuItem.prototype.activate.call(this, event);
+        PopupMenu.PopupSwitchMenuItem.prototype.activate.call(this, event);
 
         if (!this._device) {
             log('Section title activated when there is more than one device, should be non reactive');
@@ -295,10 +245,12 @@ function NMWirelessSectionTitleMenuItem() {
 }
 
 NMWirelessSectionTitleMenuItem.prototype = {
-    __proto__: NMDeviceTitleMenuItem.prototype,
+    __proto__: PopupMenu.PopupSwitchMenuItem.prototype,
 
     _init: function(client, property, title, params) {
-        NMDeviceTitleMenuItem.prototype._init.call(this, title, params);
+        params = params || { };
+        params.style_class = 'popup-subtitle-menu-item';
+        PopupMenu.PopupSwitchMenuItem.prototype._init.call(this, title, false, params);
 
         this._client = client;
         this._property = property + '_enabled';
@@ -324,7 +276,7 @@ NMWirelessSectionTitleMenuItem.prototype = {
     },
 
     activate: function(event) {
-        NMDeviceTitleMenuItem.prototype.activate.call(this, event);
+        PopupMenu.PopupSwitchMenuItem.prototype.activate.call(this, event);
 
         this._client[this._setEnabledFunc](this._switch.state);
     },
@@ -380,7 +332,7 @@ NMDevice.prototype = {
         this._overflowItem = null;
 
         if (this.device) {
-            this.statusItem = new NMDeviceTitleMenuItem(this._getDescription());
+            this.statusItem = new PopupMenu.PopupSwitchMenuItem(this._getDescription(), this.connected, { style_class: 'popup-subtitle-menu-item' });
             this._statusChanged = this.statusItem.connect('toggled', Lang.bind(this, function(item, state) {
                 if (state)
                     this.activate();